package com.kun.service_msm.controller;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import com.kun.service_msm.service.MsmService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/service_msm/msm")
@CrossOrigin
public class MsmController {
    @Autowired
    private  MsmService msmService;
    @PostMapping("send/{phone}")
    public R send(@PathVariable String phone){
        String path = "https://jumrtvie.api.bdymkt.com/sms/send";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);
        request.setCredentials("41af0651682a4caeb15f26021372119d", "7a9d43011a3b402da443169ad313979f");

        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        request.addQueryParameter("phone", phone);
        request.addQueryParameter("param", "123456");
        request.addQueryParameter("sign", "1");
        request.addQueryParameter("skin", "20");



        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }




        return R.ok();
    }

}
